package com.huang.springbootthymeleafshiro.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//给不被容器管理的类 注入需要的bean
@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
           this.context= applicationContext;
    }

    public static Object getBean(String beanname){
        return context.getBean(beanname);
    }
}
